package br.com.iswe.gwt.ui.client;

import java.util.ArrayList;
import java.util.List;

/**
 * Bean que possui as informacoes de uma propriedade mantida pela FormFactory.
 */
public class PropertyInfo {
	private List<Object> components 	  = new ArrayList<Object>();
	private List<Validator> validatorList = new ArrayList<Validator>();
	private List<ValidationHandler> validatorHandlers = null;
	
	private String name;
	private Object value;
	private int    type;
	private boolean ignore = false;
	private boolean ignoreWhenNull = false;
	private boolean onLoading = false;
	private boolean stringProperty = false;
	
	protected String listPropertyName = null;
	
	public PropertyInfo(List<ValidationHandler> validatorHandlers){
		this.validatorHandlers = validatorHandlers;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String nome) {
		this.name = nome;
	}
	
	public void setOnLoading(boolean onLoading) {
		this.onLoading = onLoading;
	}
	public boolean isOnLoading(){
		return onLoading;
	}
	
	public int getType() {
		return type;
	}
	public void setType(int tipo) {
		this.type = tipo;
	}
	
	public void addValidator(Validator validator){
		//Configura no Validator os Handlers disponiveis no form
		for (int i = 0; i < validatorHandlers.size(); i++) {
			validator.addValidationHandler(validatorHandlers.get(i));
		}
		validatorList.add(validator);
	}
	
	public List<Validator> getValidatorList() {
		return validatorList;
	}
	
	public Object getValue() {
		return value;
	}
	public void setValue(Object valor) {
		this.value = valor;
	}

	public void setIgnore(boolean ignore) {
		this.ignore = ignore;
	}
	public boolean isIgnore() {
		return ignore;
	}
	
	public List<Object> getComponents() {
		return components;
	}
	public void addComponente(Object componente) {
		this.components.add(componente);
	}

	public void setStringProperty(boolean propriedadeString){
		this.stringProperty = propriedadeString;
	}
	public boolean isString() {
		return stringProperty;
	}
	
	public String toString() {
		String valorString = "null";
		if(value != null){
			valorString = value.toString();
		}
		return name + ":" + valorString;
	}

	
	public String getListPropertyName() {
		return listPropertyName;
	}
	public void setListPropertyName(String listPropertyName){
		this.listPropertyName = listPropertyName;
	}

	public boolean isIgnoreWhenNull() {
		return ignoreWhenNull;
	}
	public void setIgnoreWhenNull(boolean value){
		ignoreWhenNull = value;
	}
}
